package com.magic.uschat.adapter;

import java.util.ArrayList;
import java.util.List;

import com.magic.uschat.bean.User;

import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;


public class SearchFriendAdapter extends RecyclerView.Adapter<SearchFriendViewHolder>{
	
	private List<User> datas = new ArrayList<User>();
	private OnRecyclerViewListener onRecyclerViewListener;
	
	
	@Override
	public int getItemCount() {
		return datas.size();
	}
	
	public void bindDats(List<User> users){
		datas.clear();
		if (users!=null) {
			datas.addAll(users);
		}
	}
	
	public void appendDatas(List<User> users){
		if (users!=null) {
			datas.addAll(users);
		}
	}
	
	public void clearData(){
		datas.clear();
	}
	
	public User getItem(int position){
		if (position<datas.size()) {
			return datas.get(position);
		}
		return null;
	}

	@Override
	public void onBindViewHolder(SearchFriendViewHolder viewHolder, int position) {
		((BaseViewHolder)viewHolder).bindData(datas.get(position));
	}

	@Override
	public SearchFriendViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		return new SearchFriendViewHolder(parent.getContext(),parent, onRecyclerViewListener);
	}

	public void setOnRecyclerViewListener(OnRecyclerViewListener listener){
		this.onRecyclerViewListener = listener;
	}
	
	
}
